<template>
	<view>
		<scroll-view scroll-y class="page">
			<!-- 头部 -->
			<cu-custom bgColor="bg-rgb" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">制具采购入库详情</block>
				<view slot="right" @tap="rightClick">凭证抬头</view>
			</cu-custom>
			<!-- 查询条件 -->
			<view class="fixed" :style="[{animationDelay: 0.1 + 's'}]">
				<form>
					<view class="cu-form-group last">
						<image class="icon" src="../../static/saomiao.png" mode=""></image>
						<input placeholder="请扫描采购明细ID" name="input" v-model="myFormData.oddNumber" @confirm="inputQuery"></input>
					</view>
				</form>
			</view>
			<!-- 详情 -->
			<view class="list">
				<view class="cu-list menu" v-if="WordListMsg.length > 0">
					<view class="cu-list menu" v-for="(item,index) in WordListMsg" :key="index">
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay:  0.8 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="headLine">采购明细({{item.rowNum}})</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 0.9 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">料号</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.materielCode}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.0 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">物料</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.materielName}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.1 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">采购数量</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.purchaseNum}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.2 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">交货日期</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.deliveryDate}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.3 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">物料主</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.materielTeam}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.4 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">库存地点</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.storageSite}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.5 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">批次</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.batchNum}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.6 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="text-grey">申请者</text>
							</view>
							<view class="action">
								<text class="text-grey">{{item.applicant}}</text>
							</view>
						</view>
						<view class="cu-item animation-slide-bottom" :style="[{animationDelay: 1.6 + (index * 0.9) + 's'}]">
							<view class="content">
								<text class="title" style="background-color: #99CC00;">收货数量：</text>
							</view>
							<view class="action">
								<input style="width: 260rpx;" type="text" v-model="preservationList[index].num" value="" placeholder="请输入收货数量" />
							</view>
						</view>
						<view class="cu-item animation-slide-bottom btns" :style="[{animationDelay: 1.7 + (index * 0.9) + 's'}]">
							<!-- <view class=""> -->
							<view class="btn1" @click="prin(item)">打印</view>
							<view class="btn2" @click="Warehousing(index)">入库</view>
							<view class="btn3" @click="scanning(index)">扫描入库</view>
							<!-- </view> -->
						</view>
					</view>
				</view>
			</view>
			<!-- 抬头凭证 输入弹窗 -->
			<view class="cu-modal" :class="modalName=='Modal'?'show':''">
				<view class="cu-dialog">
					<view class="cu-bar bg-white justify-end">
						<view class="content">凭证抬头</view>
						<view class="action">
							<text class="cuIcon-close text-red" @click="close"></text>
						</view>
					</view>
					<view class="padding-xl">
						<form>
							<view class="cu-form-group">
								<view class="titles">凭证日期：</view>
								<picker mode="date" :value="myModelData.cerDate" @change="cerDateChange">
									<view class="picker">
										{{myModelData.cerDate}}
									</view>
								</picker>
							</view>
							<view class="cu-form-group">
								<view class="titles">过账日期：</view>
								<picker mode="date" :value="myModelData.accountDate" @change="accountDateChange">
									<view class="picker">
										{{myModelData.accountDate}}
									</view>
								</picker>
							</view>
							<view class="cu-form-group">
								<view class="titles">类型：</view>
								<input placeholder="工号" style="text-align: right;" name="input" v-model="myModelData.affairType" disabled></input>
							</view>
							<view class="cu-form-group">
								<view class="titles">描述：</view>
								<textarea value="" placeholder="请输入描述" style="text-align: left;text-indent: 2em;" v-model="myModelData.affairContent" />
								</view>
							<view class="padding flex flex-direction">
								<button class="cu-btn bg-blue lg"  @click="onSubmit">确定</button>
							</view>
						</form>
					</view>
				</view>
			</view>
			<!-- 打印 输入弹窗 -->
			<view class="cu-modal" :class="modalName1=='Modal1'?'show':''">
				<view class="cu-dialog">
					<view class="cu-bar bg-white justify-end">
						<view class="content">打印</view>
						<view class="action" @tap="hideModal1">
							<text class="cuIcon-close text-red"></text>
						</view>
					</view>
					<view class="padding-xl">
						<form>
							<view class="cu-form-group">
								<view class="titles">批次数量：</view>
								<input placeholder="请输入批次数量" style="text-align: right;" name="input" type="number" v-model="myModelData1.batch"></input>
							</view>
							<view class="cu-form-group">
								<view class="titles">打印张数：</view>
								<input placeholder="请输入打印张数" style="text-align: right" type="number" v-model="myModelData1.printNum"></input>
							</view>
							<view class="padding flex flex-direction">
								<button class="cu-btn lg" @click="onSubmitPrin">确定</button>
							</view>
						</form>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name: 'toolsWarehousingDetail',
		data() {
			return {
				id: '',
				myFormData: {
					oddNumber: ''
				},
				// recriveMsg: {}, // 订单管理—采购订单-通过id查询
				WordListMsg: [], // 订单管理—采购订单子表主表ID查询
				preservationList: [],
				modalName: '',
				modalName1:'',
				myModelData1: {
					batch: '', // 批次数量
					id: '', //id 
					printNum: '' ,// 打印张数
					mobileType:'制具打印'
				},
				myModelData:{
					cerDate:'', //凭证日期
					accountDate:'', // 过账日期
					affairType:'',
					affairContent:''
				}
			}
		},
		onLoad(e) {
			this.id = uni.getStorageSync('toolsWarehousingId');
			// this.getReceiveDetail();
			this.getWordListDetail();
			let date = new Date()
			this.myModelData.cerDate = date.getFullYear() + '-' +(date.getMonth() + 1) + '-' + date.getDate();
			this.myModelData.accountDate = date.getFullYear() + '-' +(date.getMonth() + 1) + '-' + date.getDate();
			this.myModelData.affairType = uni.getStorageSync('affairType');
		},
		methods: {
			// 订单管理—采购订单-通过id查询
			// getReceiveDetail() {
			// 	let data = {
			// 		id: this.id
			// 	}
			// 	this.$http.get('order/mesOrderPurchase/queryById', {
			// 		params: data
			// 	}).then(res => {
			// 		console.log(res)
			// 		if (res.data.success) {
			// 			this.recriveMsg = res.data.result;
			// 		} else {
			// 			this.$tip.error(res.data.message)
			// 		}
			// 	})
			// },
			// 订单管理—采购订单子表主表ID查询
			getWordListDetail() {
				uni.showLoading({
					mask:true,
					title:'加载中.....'
				})
				let data = {
					id: this.id,
					materielCode: this.myFormData.oddNumber
				}
				this.$http.get('order/mesOrderPurchase/queryMesPurchaseItemByMainId', {
					params: data
				}).then(res => {
					uni.hideLoading()
					if (res.data.success) {
						this.WordListMsg = res.data.result;
						this.preservationList = []
						for (let i = 0; i < this.WordListMsg.length; i++) {
							let data = {
								id: this.WordListMsg[i].id,
								num: ''
							}
							this.preservationList.push(data)
						}
						console.log(this.WordListMsg)
					} else {
						// this.$tip.error(res.data.message)
            this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			// 输入框查询
			inputQuery() {
				console.log(this.myFormData.oddNumber)
				this.getWordListDetail();
			},
			// 入库
			// 凭证抬头 按钮
			rightClick(){
				this.modalName = 'Modal'
			},
			// 关闭弹窗
			close(){
				this.modalName = '';
				this.myModelData.affairContent = '';
			},
			// 凭证日期
			cerDateChange(e) {
				console.log(e)
				this.myModelData.cerDate = e.detail.value
			},
			accountDateChange(e){
				this.myModelData.accountDate = e.detail.value
			},
			onSubmit(){
				uni.showLoading({
					mask:true,
					title:'添加物料凭证抬头.....'
				})
				if(this.myModelData.affairContent.replace(/\s+/g, "") == ''){
					uni.hideLoading()
					// this.$tip.error('描述不能为空');
          this.modal.show({ type:'error', content:'描述不能为空' })
					return false
				}
				this.$http.post('storage/mesCertificatePerk/add',this.myModelData).then( res =>{
					console.log(res)
					uni.hideLoading()
					if(res.data.success){
						uni.setStorageSync('toolsWarehousingDetailRise',res.data.result.id);
						// this.$tip.success(res.data.message)
            this.modal.show({ type:'success', content:res.data.message })
						this.modalName = '';
						this.myModelData.affairContent = '';
					}else {
						// this.$tip.error(res.data.message)
            this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			Warehousing(index) {
				if (this.preservationList[index].num == '' || this.preservationList[index].num == 0) {
					// this.$tip.error('入库数不能为空')
          this.modal.show({ type:'error', content:'入库数不能为空' })
					return false
				}else if(!uni.getStorageSync('toolsWarehousingDetailRise')){
					this.modalName = 'Modal'
					return false
				}
				uni.showModal({
					title: '制具采购入库',
					content: '确认要入库吗',
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if (res.confirm) {
							uni.showLoading({
								mask:true,
								title:'入库中.....'
							})
							let data = {
								mobileCode:101,
								mobileType:'制具采购入库',
								perkId:uni.getStorageSync('toolsWarehousingDetailRise'),
								reserveCode:this.preservationList[index].id,
								inputNum:this.preservationList[index].num
							}
							this.$http.post('storage/mesCertificatePerk/addMesCertificateItem',data).then( res =>{
								uni.hideLoading()
								if(res.data.success){
									// this.$tip.success(res.data.message)
                  this.modal.show({ type:'success', content:res.data.message })
								}else {
									// this.$tip.error(res.data.message)
                  this.modal.show({ type:'error', content:res.data.message })
								}
							})
						}
					}
				})
			},
			// 扫描入库
			scanning(index){
				console.log(this.preservationList[index])
				if(!uni.getStorageSync('toolsWarehousingDetailRise')){
					this.modalName = 'Modal'
					return false
				}
				uni.showModal({
					title: '制具采购入库',
					content: '确认要入库吗',
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if (res.confirm) {
							uni.showLoading({
								mask:true,
								title:'入库中.....'
							})
							let data = {
								mobileCode:101,
								mobileType:'制具采购扫描入库',
								perkId:uni.getStorageSync('toolsWarehousingDetailRise'),
								reserveCode:this.preservationList[index].id,
								inputNum:this.preservationList[index].num
							}
							this.$http.post('storage/mesCertificatePerk/addMesCertificateItem',data).then( res =>{
								console.log(res.data.result.id)
								uni.hideLoading()
								if(res.data.success){
									uni.setStorageSync('toolsWarehousingDetailId',res.data.result.id)
									this.$Router.push({
										name: 'toolsWarehousingDetailSaoMiao'
									})
								}else {
									// this.$tip.error(res.data.message)
                  this.modal.show({ type:'error', content:res.data.message })
								}
							})
						}
					}
				})
			},
			hideModal(){
				this.modalName = ''
			},
			// 打印
			prin(item) {
				console.log(item)
				this.myModelData1.id = item.id;
				this.modalName1 = 'Modal1'
			},
			hideModal1(){
				this.modalName1 = ''
			},
			onSubmitPrin() {
				if (this.myModelData1.batch.replace(/\s+/g, "") == '') {
					// this.$tip.error('批次数量不能为空');
					this.modal.show({ type:'error', content:'批次数量不能为空' })
					return false
				} else if (this.myModelData1.printNum.replace(/\s+/g, "") == '') {
					// this.$tip.error('打印张数不能为空');
					this.modal.show({ type:'error', content:'打印张数不能为空' })
					return false
				}
				uni.showModal({
					title: '提示',
					content: '是否打印？',
					cancelText: '取消',
					confirmText: '打印',
					success: res => {
						if (res.confirm) {
							this.$http.get('storage/mesStorageWholesale/printAdd', {
								params: this.myModelData1
							}).then(res => {
								if (res.data.success) {
									// this.$tip.success(res.data.message)
                  this.modal.show({ type:'success', content:res.data.message })
									this.modalName1 = ''
								} else {
									// this.$tip.error(res.data.message)
                  this.modal.show({ type:'error', content:res.data.message })
								}
							})
						}
					}
				})
			}
		},
	}
</script>

<style lang="less">
	page {
		background-color: white;
		.fixed {
			position: fixed;
			z-index: 1;
			width: 100%;
			background-color: white;
			height: 100rpx;
			border-bottom: 1rpx solid #eee;
		
			.last {
				border-bottom: 1rpx solid #eee;
				position: relative;
		
				.icon {
					width: 30rpx;
					height: 29rpx;
					position: absolute;
					top: 36rpx;
					left: 60rpx;
				}
		
				input {
					width: 686rpx;
					height: 68rpx;
					background: #FFFFFF;
					border: 1px solid #D5D8DF;
					border-radius: 34px;
					padding-left: 79rpx;
				}
			}
		}
		.list {
			margin-top: 120rpx;
			.headLine{
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #191919;
				line-height: 50rpx;
			}
			input {
				border: 2rpx solid #F0F0F0;
				height: 60rpx;
				padding: 10rpx;
				border-radius: 10rpx;
				font-size: 20rpx;
			}
			.title {
				font-weight: bold;
				padding: 10rpx;
				border-radius: 10rpx;
				color: white;
			}
			.btns {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 20rpx;
				font-size: 25rpx;
				padding: 20rpx 30rpx;
			
				view {
					width: 180rpx;
					height: 64rpx;
					line-height: 50rpx;
					color: white;
					border-radius: 30rpx;
					padding: 10rpx 20rpx;
					text-align: center;
				}
			
				.btn1 {
					background-image: radial-gradient(circle, #3F55E9, #5F71ED, #7D8CF0);
				}
			
				.btn2 {
					background-image: radial-gradient(circle, #716BA9, #362D85, #57509A);
				}
			
				.btn3 {
					background-image: radial-gradient(circle, #354D9E, #354D9E, #697BB7);
				}
			}
		}
	}
	.cu-btn{
		color: white;
		background-image: radial-gradient(circle, #3F55E9, #5F71ED, #7D8CF0);
	}
</style>
